<?php

namespace partner\functions\wechat\lib;

use Exception;
use WeChatPay\Crypto\Rsa;
use WeChatPay\Util\MediaUtil;

class Utils
{
    static public function getEncrypt(string $public_key_path = '', string $str = '')
    {
        if (empty($public_key_path) || ! file_exists($public_key_path))
            throw new Exception("证书不存在或证书路径为空");
        if (empty($str))
            throw new Exception("加密字符串不能为空");

        $wechat_rsa_instance = Rsa::from($public_key_path, Rsa::KEY_TYPE_PUBLIC);
        return Rsa::encrypt($str, $wechat_rsa_instance);
    }
}